package com.lemon.smartsafetynew.ui.adapter.record;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.record.MetalVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by JiangAn on 2018/5/24.
 */

public class MetalInfoAdapter extends LemonRcvAdapter<MetalVo> {
    private RecyclerTClickListener<MetalVo> mListener;

    public MetalInfoAdapter(@Nullable List<MetalVo> data, RecyclerTClickListener<MetalVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new MetalInfoAdapter.MetalItem();
    }

    public class MetalItem implements AdapterItem<MetalVo> {

        @Bind(R.id.tv_space_name)
        TextView tvSpaceName;
        @Bind(R.id.tv_metal_type)
        TextView tvMetalType;
        @Bind(R.id.tv_metal_main_product)
        TextView tvMetalMainProduct;
        @Bind(R.id.tv_is_carrier_move)
        TextView tvIsCarrierMove;
        @Bind(R.id.tv_is_metaling)
        TextView tvIsMetaling;
        @Bind(R.id.tv_heating_type)
        TextView tvHeatingType;
        @Bind(R.id.item_layout)
        LinearLayout itemLayout;

        private MetalVo data;
        private int pos;

        @Override
        public int getLayoutResId() {
            return R.layout.layout_metal_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            itemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data, pos);
                }
            });
        }

        @Override
        public void handleData(MetalVo metalVo, int position) {
            data = metalVo;
            pos = position;

            tvSpaceName.setText(CommonUtil.avoidNullString(metalVo.getCode_name()));
            tvMetalType.setText(CommonUtil.avoidNullString(metalVo.getTypeName()));
            tvMetalMainProduct.setText(CommonUtil.avoidNullString(metalVo.getMain_product()));
            tvIsCarrierMove.setText(CommonUtil.avoidNullString(metalVo.getIsMove()));
            tvIsMetaling.setText(CommonUtil.avoidNullString(metalVo.getIsMelting()));
            tvHeatingType.setText(CommonUtil.avoidNullString(metalVo.getHeating()));
        }
    }
}

